<?php
class ArticleController extends Apps_Controller_Action_Default {

	// One Article
    public function visaAction() {
        $articleModel = new M_Article();
        $visa = $articleModel->getArticleByType(M_DbTable_Article::REFERENCE_TYPE_VISA);
        $this->setPagination($visa, $this->_request, 5);
    }

    //about us
    public function aboutUsAction() {
        $articleModel = new M_Article();
        $aboutUs = $articleModel->getArticleByType(M_DbTable_Article::REFERENCE_TYPE_ABOUT)->query()->fetch();
        $this->view->visa = $aboutUs;
    }

    public function whyVctAction() {
    	$articleModel = new M_Article();
    	$vct = $articleModel->getArticleByType(M_DbTable_Article::REFERENCE_WHY_VCT)->query()->fetch();
    	$this->view->vct = $vct;
    }

    public function bookingGuideAction() {
    	$articleModel = new M_Article();
    	$guide = $articleModel->getArticleByType(M_DbTable_Article::REFERENCE_BOOKING_GUIDE)->query()->fetch();
    	$this->view->guide = $guide;
    }

    public function vctHistoryAction() {
    	$articleModel = new M_Article();
    	$history = $articleModel->getArticleByType(M_DbTable_Article::REFERENCE_VCT_HISTORY)->query()->fetch();
    	$this->view->history = $history;
    }

    // Many Article
    public function faqsAction() {
    	$rq = $this->_request;
		$faqModel = new M_Faqs();

        $faqsCategoryModel = new M_FaqsCategory();
        $listFaqsCategory  = $faqsCategoryModel->getAllFaqsCategory()->query()->fetchAll();

        if($listFaqsCategory) {
            foreach($listFaqsCategory as $k => $v) {
        		$listFaqsCategory[$k]['list_faqs'] = $faqModel->getFaqsByCategoryId($v['id'])->query()->fetchAll();
            }
        }
		$this->view->listFaqs = $listFaqsCategory;
    }

    public function travelGuideAction() {
    	$rq = $this->_request;
    	$travelId = intval($rq->getParam('id'));
    	$articleModel = new M_Article();

    	if(is_numeric($travelId) && $travelId !== 0) {
    		$guide = $articleModel->getArticleById($travelId)->query()->fetch();
    		if($guide['reference_type'] != M_DbTable_Article::REFERENCE_TRAVEL_GUIDE) {
    			$this->_flashMessenger->addMessage(self::$msgNoRecordFound);
    			$this->goToControllerIndex();
    		} else {
	    		$otherLink = $articleModel->getMultiArticleByType(M_DbTable_Article::REFERENCE_TRAVEL_GUIDE, $guide['id'])->query()->fetchAll();
    		}
    	} else {
	    	$guide = $articleModel->getArticleByType(M_DbTable_Article::REFERENCE_TRAVEL_GUIDE)->query()->fetch();
	    	$otherLink = $articleModel->getMultiArticleByType(M_DbTable_Article::REFERENCE_TRAVEL_GUIDE, $guide['id'])->query()->fetchAll();
    	}

    	$this->view->guide = $guide;
    	$this->view->otherLink = $otherLink;
    }

    public function careerAction() {
    	$rq = $this->_request;
    	$careerId = intval($rq->getParam('id'));
    	$articleModel = new M_Article();

    	if(is_numeric($careerId) && $careerId !== 0) {
    		$guide = $articleModel->getArticleById($careerId)->query()->fetch();
    		if($guide['reference_type'] != M_DbTable_Article::REFERENCE_CAREER) {
    			$this->_flashMessenger->addMessage(self::$msgNoRecordFound);
    			$this->goToControllerIndex();
    		} else {
	    		$otherLink = $articleModel->getMultiArticleByType(M_DbTable_Article::REFERENCE_TRAVEL_GUIDE, $guide['id'])->query()->fetchAll();
    		}
    	} else {
	    	$guide = $articleModel->getArticleByType(M_DbTable_Article::REFERENCE_CAREER)->query()->fetch();
	    	$otherLink = $articleModel->getMultiArticleByType(M_DbTable_Article::REFERENCE_TRAVEL_GUIDE, $guide['id'])->query()->fetchAll();
    	}

    	$this->view->guide = $guide;
    	$this->view->otherLink = $otherLink;
    }
    
    public function detailAction() {
    	$id = intval($this->_request->getParam('id'));
    	$t  = intval($this->_request->getParam('t'));
    
    	$articleModel = new M_Article();
    	$article = $articleModel->getArticleById($id)->query()->fetch();
    	if(!$id || !$t || !$article) {
    		//$this->_redirect('');
    	} else {
    		$this->view->article = $article;
    
    		$this->view->otherLink = $articleModel->listOtherArticle($t, $id)->query()->fetchAll();
    	}
    
    	$type = array(
    			M_DbTable_Article::REFERENCE_TYPE_VISA   	=> 'Visa_&_Ticket',
    			M_DbTable_Article::REFERENCE_TRAVEL_GUIDE	=> 'Travel_Guide',
    			M_DbTable_Article::REFERENCE_BOOKING_GUIDE	=> 'Booking_Guide',
    			M_DbTable_Article::REFERENCE_CAREER	        => 'Carrer'
    	);
    	$this->view->labelType = isset($type[$t]) ? $type[$t] : $type[M_DbTable_Article::REFERENCE_TYPE_VISA];
    	$this->view->t = $t;
    
    	//meta tag
//     	$tbVctSetting = new M_DbTable_VctSetting();
//     	$vctSetting   = $tbVctSetting->getMetaTag();
//     	$this->_page_meta_keywords    = $article['meta_keyword'] ? $article['meta_keyword'] : ($vctSetting['meta_keyword'] ? $vctSetting['meta_keyword'] : $this->_default_keyword);
//     	$this->_page_meta_description = $article['meta_description'] ? $article['meta_description'] : ($vctSetting['meta_description'] ? $vctSetting['meta_description'] : $this->_default_description);
//     	$this->_page_title 	  		  = $article['header_title'] ? $article['header_title'] : ($vctSetting['header_title'] ? $vctSetting['header_title'] : $this->_default_header_title);
    }
}